package com.ytjj.qmyx.mall.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ytjj.qmyx.mall.mapper.FunctionConfigDao;
import com.ytjj.qmyx.mall.mapper.HomePageDao;
import com.ytjj.qmyx.mall.model.YxFunctionConfig;
import com.ytjj.qmyx.mall.model.YxFunctionConfigNewuser;
import com.ytjj.qmyx.mall.model.YxFunctionConfigNewuserDto;
import com.ytjj.qmyx.mall.model.response.IconResponse;
import com.ytjj.qmyx.mall.model.response.NewBannersResponse;
import com.ytjj.qmyx.mall.service.HomePageService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class HomePageServiceImpl implements HomePageService {

    @Resource
    private HomePageDao homePageDao;

    @Resource
    private FunctionConfigDao functionConfigDao;

    @Override
    public List<NewBannersResponse> findBannersByType(Integer type) {
        return homePageDao.findBannersByType(type);
    }

    @Override
    public List<IconResponse> findIconByType(String type) {
        return homePageDao.findIconByType(type);
    }

    @Override
    public Map getDetailById(Integer id, String source) {
        if(1==id){
            YxFunctionConfigNewuser vo = functionConfigDao.selectByEventId(id);
            if(null==vo){
                return  null;
            }
            YxFunctionConfigNewuserDto dto = new YxFunctionConfigNewuserDto();
            BeanUtils.copyProperties(vo, dto);
            YxFunctionConfig config = functionConfigDao.selectById(id);
            dto.setName(config.getName());
            dto.setDesc(config.getDesc());
            //return dto;

            String jsonStr = JSONObject.toJSONString(dto);
            return JSONObject.parseObject(jsonStr);
        }

        if(2==id){
            if("wxH5Alone".equals(source) || "webH5Alone".equals(source)){
                source = "h5";
            }
            if("wxH5Platform".equals(source) || "webH5Platform".equals(source)){
                source = "h5Platform";
            }
            Map map = functionConfigDao.getFunctionConfigKefu(source);
            return  map;
        }
        return null;
    }

}
